# Maintainer: Johannes Löthberg <johannes@kyriasis.com>
# Maintainer: Thore Bödecker <foxxx0@archlinux.org>
# Contributor: Bartłomiej Piotrowski <bpiotrowski@archlinux.org>
# Contributor: Andreas Radke <andyrtr@archlinux.org>
# Contributor: Peter Lewis <plewis@aur.archlinux.org>
# Contributor: Sebastian Köhler <sebkoehler@whoami.org.uk>

# This must be built against the version of dovecot being used,
# else mail delivery will fail.
# Specify the version of dovecot to be used here:
_dcpkgver=2.3.20
# Make sure to bump pkgrel if changing this.

_dcmajor="$(awk -F'.' '{printf "%d.%d", $1, $2}' <<< "${_dcpkgver}")"

pkgname=pigeonhole
pkgver=0.5.20
pkgrel=1

pkgdesc='Sieve implementation for Dovecot'
url='https://pigeonhole.dovecot.org/'
arch=('loong64' 'x86_64')
license=('LGPL')

depends=("dovecot=${_dcpkgver}")

conflicts=('dovecot-sieve' 'pigeonhole-hg')

source=("https://pigeonhole.dovecot.org/releases/2.3/dovecot-${_dcmajor}-pigeonhole-${pkgver}.tar.gz"{,.sig})

sha256sums=('ae32bd4870ea2c1328ae09ba206e9ec12128046d6afca52fbbc9ef7f75617c98'
            'SKIP')
validpgpkeys=(
  '42F3CD50D4F25A41833BEE3704D62B1E3DFBB4F4' # Stephan Bosch <stephan@rename-it.nl>
  '2BE74AAB3EE754DFB9C80D3318A348AEED409DA1'
)


prepare() {
  cd "dovecot-${_dcmajor}-pigeonhole-${pkgver}"

  local filename
  for filename in "${source[@]}"; do
    if [[ "$filename" =~ \.patch$ ]]; then
      patch -p1 -N -l -i "$srcdir/${filename##*/}"
    fi
  done
}

build() {
  cd "dovecot-${_dcmajor}-pigeonhole-${pkgver}"

  ./configure \
    --prefix=/usr \
    --with-dovecot=/usr/lib/dovecot \
    --with-moduledir=/usr/lib/dovecot/modules \
    --disable-static
  make
}

check() {
  cd "dovecot-${_dcmajor}-pigeonhole-${pkgver}"
  make check
}

package() {
  cd "dovecot-${_dcmajor}-pigeonhole-${pkgver}"

  make DESTDIR="$pkgdir" install
}
